package shenxg.game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ScenePrint {

	static int x = 44;
	static int y = 223;
	static int width = 68;
	
	static int countScene = 0;
	
	static final int SmallstScoreToPrint = 3000;
	
	
	public static void printSceneAndParents(Scene scene) throws IOException{
		System.out.println("scene.getFinalScore() : " + scene.getFinalScore());
		
		countScene = scene.getFinalScore();
		if(countScene < SmallstScoreToPrint)
			return;
		int amount = 0;
		File imgFile = new File("e:/temp/1.jpg");
		
		while(scene != null) {
			File imgOutput = new File("e:/temp/1_out_print_" +countScene + "_" + amount+".jpg");
			printOneScene(scene, imgFile, imgOutput);
			amount++;
			scene = scene.sceneParent;
		}

	}
	
	public static void printOneScene(Scene scene, File imgFile, File outFile) throws IOException {
		BufferedImage image = null;
		
		image = ImageIO.read(imgFile);
		Graphics g = image.getGraphics();
		
		for (int j = 0; j < Scene.X_LENGTH; j++) {
			for (int i = 0; i < Scene.Y_LENGTH; i++) {
				Color color;
				if(null == scene.items[j][i]) {
					color = new Color(255,255,255);
				} else {
					color = scene.items[j][i].getColorType().getColor();
				}
				
				g.setColor(color);
				g.fillRect(x + width * j, y + width * i, width, width);
			}
		}

		g.drawRect(x, y, width, width);

		ImageIO.write(image, "jpg", outFile);
	}
}
